<template>
  <div>
    <Card>
      <div class="marginB10 f_16 ">
        {{topTitle}}
      </div>
      <Table
        :data="tableData"
        :columns="columns"
        stripe
        border
        class="marginB10"
        :loading="loading"
        :height="$app.winHeight-225"
      ></Table>
      <Page
        :total="total"
        show-sizer
        show-total
        show-elevator
        size="small"
        :page-size="pageSize"
        :page-size-opts="$app.pageAll.pageSizeOpts"
        :current="page"
        @on-change="loadMore"
        @on-page-size-change="changePageSize"
      ></Page>
    </Card>
    
  </div>
</template>

<script>
export default {
  name: "pW_List_warn",
  components: {},
  data() {
    let {
      $route:{
        query:{
          type
        }
      }
    }=this;

    let data = {
      type,
      tableData: [],
      columns: []
    };

    //分页相关
    let tool = {
      loading: true, //加载时显示转转
      total: 0, //总页数
      page: 1, //当前页码
      pageSize: $app.pageAll.pageSize //分页条数，最低15条
    };
    return Object.assign(data, tool); // 对象合并
  },
  computed: {
    topTitle () {
      let {type}=this;
      let out='专利撰写 - ';
      switch( parseInt(type) ){
        case 1:
          out+='补充资料';
        break;
        case 2:
          out+='未读留言';
        break;
        case 3:
          out+='待确认';
        break;
      };
      return out;
    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    //获取数据
    getData() {
      // 清空原本的数据
      this.loading=true;
      this.columns=[];
      this.tableData=[];

      let {
        type,
        $route
      }=this;

      let { page, pageSize } = this;
      if(type==1){
        // 专利撰写 - 补充资料
	      $ajax.schedule_patentWriteNotInfo({ page, pageSize }, resData => {
          let listT=[
            {
              title: " ",
              type: "index",
              width: 30,
              align: "center ",
              className: "goOnTxt c999"
            },
            {
              title: "商品",
              key: "goods_name",
              className: "goOnTxt",
              resizable: true,
            },
            {
              title: "专利名称",
              className: "goOnTxt",
              key: "name",
              resizable: true,
            },
            {
              title: "下单日期",
              className: "goOnTxt",
              key: "created_at",
              width:180,
              resizable: true,
            }
          ];
          this.ajaxBack(listT,resData);
        });
      }else if(type==2){
        //专利撰写 - 未读留言列表
	      $ajax.schedule_patentWriteUnReadContact({ page, pageSize }, resData => {
          let listT=[
            {
              title: " ",
              type: "index",
              width: 30,
              align: "center ",
              className: "goOnTxt c999"
            },
            {
              title: "专利名称",
              className: "goOnTxt",
              key: "patent_name",
              resizable: true,
            },
            {
              title: "下单日期",
              className: "goOnTxt",
              key: "created_at",
              width:180,
              resizable: true,
            },
            {
              title: "消息内容",
              className: "goOnTxt",
              key: "message",
              resizable: true,
            }
          ];
          this.ajaxBack(listT,resData);
        });
      }else if(type==3){
        //专利撰写 - 待确认列表
	      $ajax.schedule_patentWriteConfirm({ page, pageSize }, resData => {
          let listT=[
            {
              title: " ",
              type: "index",
              width: 30,
              align: "center ",
              className: "goOnTxt c999"
            },
            {
              title: "商品",
              key: "goods_name",
              className: "goOnTxt",
              resizable: true,
            },
            {
              title: "专利名称",
              className: "goOnTxt",
              key: "patent_name",
              resizable: true,
            },
            {
              title: "下单日期",
              className: "goOnTxt",
              key: "created_at",
              width:180,
              resizable: true,
            }
          ];
          this.ajaxBack(listT,resData);
        });
      }else{
        $app.toast('参数错误',false);
        $app.closeTag($route)//关闭本页面
      }
    },
    
    ajaxBack(listT,resData){
      
      let {type}=this;
      console.log('type = ',type)

      let textName='';

      switch( parseInt(type) ){
        case 1:
          textName='立即补充';
        break;
        case 2:
          textName='立即查看';
        break;
        case 3:
          textName='立即确认';
        break;
      };

      listT.push({
      title: "操作",
      width:180,
      className: "goOnTxt",
      render: (h, params) => {
        let {
          row: {
            order_id
          }
        } = params;
        let out = [];


        out.push(
          h(
            "span",
            {
              class: "  cBlue textLink marginR20",
              on: {
                click: () => {
                  this.$router.push({
                    name:'patentThird',
                    query: {
                      order_id
                    }
                  });
                }
              }
            },
            '查看详情'
          ),
          h(
            "span",
            {
              class: "  cBlue textLink",
              on: {
                click: () => {
                  this.$router.push({
                    name:'patentThird',
                    query: {
                      order_id,
                      pW_List_warn:type
                    }
                  });
                }
              }
            },
            textName
          )
        );



        return out;
      }
    });

      this.columns=listT;
      this.loading=false;
      this.tableData = resData.list;
      this.total = resData.total;
    },
    // 加载更多
    loadMore(page) {
      this.page = page;
      this.$nextTick(() => {
        this.getData();
      });
    },
    // 数据返回条
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.page = 1;
      this.$nextTick(() => {
        this.getData();
      });
    }
  }
};
</script>

